//
//  QZChectTool.m
//  guideBook-tourists
//
//  Created by 上官惠阳 on 16/3/11.
//  Copyright © 2016年 上官惠阳. All rights reserved.
//  做一些简单的检测处理

#import "QZChectTool.h"

@implementation QZChectTool
//判断
//判断是否为正确的邮箱
+ (BOOL)isValidateEmail:(NSString *)Email
{
    NSString *emailCheck = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",emailCheck];
    return [emailTest evaluateWithObject:Email];
}
//判断是否为正确的电话号码
+ (BOOL)isMobileNumber:(NSString *)mobileNum
{
    NSString * MOBILE = @"^1[3|4|5|7|8]\\d{9}$";//手机号
    NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";//大陆地区固话及小灵通
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    NSPredicate *regextestphs = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", PHS];
    
    if (([regextestmobile evaluateWithObject:mobileNum] == YES)
        || ([regextestphs evaluateWithObject:mobileNum] == YES)){
        return YES;
    }else{
        return NO;
    }
}
//判断是否为正确的手机号
+ (BOOL)isPhoneNumber:(NSString *)phoneNum
{
    NSString * MOBILE = @"^1[3|4|5|7|8]\\d{9}$";//手机号
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    
    return [regextestmobile evaluateWithObject:phoneNum];
}
//判断一个字符串是否都是数字
+(BOOL)isPureInt:(NSString *)string
{
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return [scan scanInt:&val] && [scan isAtEnd];
}
//判断是否是正确的qq号
+(BOOL)isValidateQQ:(NSString *)qq
{
    NSString *qqStr = @"^\\d{5,10}$";
    NSPredicate *qqPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",qqStr];
    
    return [qqPredicate evaluateWithObject:qq];
}
//判断是否是正确的微信号
+(BOOL)isValidateWechat:(NSString *)wechate
{
    NSString *wechateStr = @"^[a-zA-Z][a-zA-Z\\d_-]{5,19}$";
    NSPredicate *wechatePre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",wechateStr];

    if(wechate.length < 6 || wechate.length > 20){
        return NO;
    }
    return [wechatePre evaluateWithObject:wechate];
}
//判断是否为正确的身份证号
+(BOOL)isIDNumber:(NSString *)numStr
{
    NSString *numMatche = @"^(\\d{14}|\\d{17})(\\d|[xX])$";
    NSPredicate *numberPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",numMatche];

    return [numberPredicate evaluateWithObject:numStr];
}
//判断是否含有表情
+ (BOOL)stringContainsEmoji:(NSString *)string
{
    __block BOOL returnValue = NO;

    [string enumerateSubstringsInRange:NSMakeRange(0, [string length])
                               options:NSStringEnumerationByComposedCharacterSequences
                            usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
                                const unichar hs = [substring characterAtIndex:0];
                                if (0xd800 <= hs && hs <= 0xdbff) {
                                    if (substring.length > 1) {
                                        const unichar ls = [substring characterAtIndex:1];
                                        const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
                                        if (0x1d000 <= uc && uc <= 0x1f77f) {
                                            returnValue = YES;
                                        }
                                    }
                                } else if (substring.length > 1) {
                                    const unichar ls = [substring characterAtIndex:1];
                                    if (ls == 0x20e3) {
                                        returnValue = YES;
                                    }
                                } else {
                                    if (0x2100 <= hs && hs <= 0x27ff) {
                                        returnValue = YES;
                                    } else if (0x2B05 <= hs && hs <= 0x2b07) {
                                        returnValue = YES;
                                    } else if (0x2934 <= hs && hs <= 0x2935) {
                                        returnValue = YES;
                                    } else if (0x3297 <= hs && hs <= 0x3299) {
                                        returnValue = YES;
                                    } else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b || hs == 0x2b50) {
                                        returnValue = YES;
                                    }
                                }
                            }];

    return returnValue;
}
//6-20由数字，字母，符号组成的字符串
+(BOOL)isValidatePassword:(NSString *)pwdString
{
    NSString *pwd = @"^[A-Za-z0-9\\@\\!\\#\\$\\%\\^\\&\\*\\.\\~]{6,20}$";
    NSPredicate *regextestPassword = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pwd];

    return [regextestPassword evaluateWithObject:pwdString];
}
//是否为汉字
+(BOOL)isChineseCharacter:(NSString *)cahStr
{
    NSString *cha = @"^[\u4e00-\u9fa5]{1,}$";
    NSPredicate *regextestCah = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", cha];

    return [regextestCah evaluateWithObject:cahStr];
}
//是否为字母
+(BOOL)isEnglishWord:(NSString *)englishWord
{
    NSString *english = @"^[A-Za-z]+${1,}";
    NSPredicate *regextestEnglish = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", english];

    return [regextestEnglish evaluateWithObject:englishWord];
}
//检索是否含有敏感词汇
+(BOOL)isContainSensitive:(NSString *)string
{
    NSArray *arr = @[@"汇款",@"发货",@"合同",@"转账",@"银行",@"手机号",@"手机号码",@"银行号码",@"QQ",@"QQ号码",@"微信"];
    for (NSString *str in arr) {
        BOOL isCon = [string containsString:str];
        if (isCon) {
            return YES;
        }
    }
    return NO;
}
@end
